package com.M10.BE.database;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

import com.M10.BE.entity.DownInventoryDetail;
import com.M10.BE.entity.NAsset;
import com.fn.useries.model.Inventory;

import java.util.ArrayList;

/**
 * Created by Administrator on 2018/8/8.
 */

public class TableInventory {

    public static boolean insertInventory(Context ctx, DownInventoryDetail inventory) {
        boolean result = true;
        ContentValues cv = new ContentValues();
        cv.put(Constants.INVENTORY_ID, inventory.getId());
        cv.put(Constants.INVENTORY_JUDGEUSER, inventory.getJudgeUser());
        cv.put(Constants.INVENTORY_ORDERNO, inventory.getOrderNO());
        cv.put(Constants.INVENTORY_ORGNAME, inventory.getOrgName());
        cv.put(Constants.INVENTORY_QUERYCOUNT, inventory.getQueryCount());
        cv.put(Constants.INVENTORY_SEAMOUNT, inventory.getSEAmount());
        cv.put(Constants.INVENTORY_SETIME, inventory.getSETime());
        try {
            ctx.getContentResolver().insert(Constants.CONTENT_C_INVENTORY_URI, cv);
        } catch (Exception e) {
            e.printStackTrace();
            result = false;
        }
        return result;
    }

    public static ArrayList<DownInventoryDetail> searchInventory(Context ctx) {
        ArrayList<DownInventoryDetail> result = new ArrayList<DownInventoryDetail>();
        Cursor cursor = ctx.getContentResolver().query(Constants.CONTENT_C_INVENTORY_URI, null,
                null, null, null);
        if (cursor != null && cursor.moveToFirst()) {
            for (int i = 0; i < cursor.getCount(); i++) {
                DownInventoryDetail downInventoryDetail = new DownInventoryDetail();
                downInventoryDetail.setId(cursor.getString(cursor.getColumnIndex(Constants.INVENTORY_ID)));
                downInventoryDetail.setJudgeUser(cursor.getString(cursor.getColumnIndex(Constants.INVENTORY_JUDGEUSER)));
                downInventoryDetail.setOrderNO(cursor.getString(cursor.getColumnIndex(Constants.INVENTORY_ORDERNO)));
                downInventoryDetail.setOrgName(cursor.getString(cursor.getColumnIndex(Constants.INVENTORY_ORGNAME)));
                downInventoryDetail.setQueryCount(cursor.getString(cursor.getColumnIndex(Constants.INVENTORY_QUERYCOUNT)));
                downInventoryDetail.setSEAmount(cursor.getString(cursor.getColumnIndex(Constants.INVENTORY_SEAMOUNT)));
                downInventoryDetail.setSETime(cursor.getString(cursor.getColumnIndex(Constants.INVENTORY_SETIME)));
                result.add(downInventoryDetail);
            }
        }
        return result;
    }
}
